package com.wanxing.sellerapp.upload;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;


public class ReSyncToServiceDelay implements Delayed {


    private final long expire; // 过期时间
    // 重传文件名称
    private final String orderId;
    private final String id;
    private final String status;

    public ReSyncToServiceDelay(String orderId, String status, String id) {
        // 默认3秒后重传
        this.expire = System.currentTimeMillis() + 3 * 1000;
        this.orderId = orderId;
        this.id = id;
        this.status = status;
    }

    public ReSyncToServiceDelay(long delayTime, String orderId, String status, String id) {
        this.expire = System.currentTimeMillis() + delayTime;
        this.orderId = orderId;
        this.status = status;
        this.id = id;
    }

    @Override
    public long getDelay(@NotNull TimeUnit timeUnit) {
        return timeUnit.convert(this.expire - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(@NotNull Delayed o) {
        long f = this.getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS);
        return (int) f;
    }

    public String getOrderId() {
        return orderId;
    }

    public String getStatus() {
        return status;
    }

    public String getId() {
        return id;
    }
}
